import 'package:flutter/material.dart';
import 'package:color_dart/color_dart.dart';
import 'package:im_flutter_sdk_example/jsonserialize/serve/data.dart';
import 'package:im_flutter_sdk_example/utils/constants.dart';
import 'package:im_flutter_sdk_example/utils/global.dart';
import 'package:im_flutter_sdk_example/utils/time_util.dart';
import 'package:im_flutter_sdk_example/utils/screen.dart';

class ServeItem extends StatelessWidget {
  final bool showFollow;
  final ServeData item;
  const ServeItem({Key key, this.item, this.showFollow = false})
      : super(key: key);

  Widget _buildImage(String path) {
    return Image.network(
      path,
      // G.thumbImage112_80(path),
      width: 214.w,
      height: 154.h,
      fit: BoxFit.cover,
    );
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => {G.pushNamed('/serve_detail', arguments: item)},
      child: Container(
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border(
                bottom: BorderSide(width: 1, color: rgba(235, 235, 235, 1)))),
        padding: EdgeInsets.symmetric(
          vertical: 36.h,
        ),
        child: Column(children: [
          if (showFollow)
            Container(
              padding: EdgeInsets.only(bottom: 10),
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Image.asset(
                          'lib/assets/images/default_avatar.png',
                          width: 28,
                          height: 28,
                          fit: BoxFit.cover,
                        ),
                        Container(
                            child: Text('云南国科智融科技发展有限公司',
                                style: TextStyle(
                                    color: rgba(136, 135, 135, 1),
                                    fontSize: 14)),
                            margin: EdgeInsets.only(left: 10)),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Container(
                            height: 22,
                            padding: EdgeInsets.symmetric(horizontal: 6),
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(11),
                              border: Border.all(
                                color: rgba(25, 109, 236, 1),
                                width: 1,
                              ),
                            ),
                            child: Text('+ 关注',
                                style: TextStyle(
                                    color: rgba(25, 109, 236, 1),
                                    fontSize: 12)),
                            margin: EdgeInsets.only(left: 3)),
                      ],
                    ),
                  ]),
            ),
          Container(
            height: 77,
            child: Row(
              children: [
                _buildImage(item.advertisingMap),
                Expanded(
                  child: Padding(
                    padding: const EdgeInsets.only(left: 10),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          '${item.serviceName}',
                          style: mainTitleStyle,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                        Row(
                          children: [
                            Text(
                              '发布时间：',
                              style: TextStyle(
                                  color: rgba(163, 163, 163, 1),
                                  fontSize: 24.nsp),
                            ),
                            Text(
                              '${TimeUtil.stringFromDateTime(item.createTime)}',
                              style: TextStyle(
                                  color: rgba(163, 163, 163, 1),
                                  fontSize: 24.nsp),
                            )
                          ],
                        ),
                        Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Row(
                                children: [
                                  SizedBox(
                                    width: 9,
                                    height: 11,
                                    child: Image.asset(
                                      'lib/assets/images/label/label_position.png',
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                  Padding(
                                    padding: EdgeInsets.only(left: 5),
                                    child: Text(
                                      '${item.userInforCompany.cityName}',
                                      style: TextStyle(
                                          color: rgba(152, 152, 152, 1),
                                          fontSize: 24.nsp),
                                    ),
                                  ),
                                ],
                              ),
                              item.negotiable == 1
                                  ? Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.baseline,
                                      children: [
                                        Text(
                                          '面议',
                                          style: TextStyle(
                                              color: rgba(235, 101, 13, 1),
                                              fontSize: 28.nsp,
                                              fontWeight: FontWeight.bold),
                                        ),
                                      ],
                                    )
                                  : Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.baseline,
                                      children: [
                                        Padding(
                                          padding: EdgeInsets.only(right: 4),
                                          child: Text(
                                            '¥',
                                            style: TextStyle(
                                              color: rgba(235, 101, 13, 1),
                                              fontSize: 22.nsp,
                                            ),
                                          ),
                                        ),
                                        Text(
                                          '${item.price}',
                                          style: TextStyle(
                                              color: rgba(235, 101, 13, 1),
                                              fontSize: 32.nsp,
                                              fontWeight: FontWeight.bold),
                                        ),
                                      ],
                                    )
                            ])
                      ],
                    ),
                  ),
                )
              ],
            ),
          )
        ]),
      ),
    );
  }
}
